//
//  IGiGalleryShareView.m
//  jingdongfang
//
//  Created by BOE on 2017/8/23.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "IGiGalleryShareView.h"
#import "KLCPopup.h"

@interface IGiGalleryShareView()

@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *idLabel;
@property (nonatomic, strong) IGiGalleryEqu *model;
    
@end

@implementation IGiGalleryShareView

+ (void)showIgalleryCard:(IGiGalleryEqu *)model {
    IGiGalleryShareView *shareView = [[IGiGalleryShareView alloc] initWithFrame:CGRectMake(0, 0, 280, 320)];
    shareView.model = model;
    shareView.backgroundColor = [UIColor whiteColor];
    shareView.layer.masksToBounds = YES;
    shareView.layer.cornerRadius = 5;
    shareView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    shareView.layer.borderWidth = 1.0;
    [shareView show];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.imgView];
        [self addSubview:self.idLabel];
        
        [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(200);
            make.left.mas_equalTo(40);
            make.top.mas_equalTo(30);
        }];
        
        [self.idLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.imgView.mas_bottom).offset(20);
            make.left.mas_equalTo(self.imgView);
            make.right.mas_equalTo(self.imgView);
            make.height.mas_equalTo(30);
        }];

    }
    return self;
}

- (void)setModel:(IGiGalleryEqu *)model {
    _model = model;
    
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:self.model.codeImage]];
    _idLabel.text = [NSString stringWithFormat:@"ID:%@", self.model.macId];
}

- (void)show {
    KLCPopup *pop = [KLCPopup popupWithContentView:self showType:KLCPopupShowTypeSlideInFromTop dismissType:KLCPopupDismissTypeSlideOutToBottom maskType:KLCPopupMaskTypeDimmed dismissOnBackgroundTouch:YES dismissOnContentTouch:NO];
    [pop show];
}

- (UIImageView *)imgView {
    if (!_imgView) {
        _imgView = [[UIImageView alloc] init];
        _imgView.backgroundColor = [UIColor mainBackgroundColor];
    }
    return _imgView;
}

- (UILabel *)idLabel {
    if (!_idLabel) {
        _idLabel = [[UILabel alloc] init];
        _idLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _idLabel;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
